<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>netaddr.strategy.IPv4StrategyOpt</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="netaddr-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            >netaddr</th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="netaddr-module.html">Package&nbsp;netaddr</a> ::
        <a href="netaddr.strategy-module.html" onclick="show_private();">Module&nbsp;strategy</a> ::
        Class&nbsp;IPv4StrategyOpt
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="netaddr.strategy.IPv4StrategyOpt-class.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== CLASS DESCRIPTION ==================== -->
<h1 class="epydoc">Class IPv4StrategyOpt</h1><p class="nomargin-top"><span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt">source&nbsp;code</a></span></p>
<pre class="base-tree">
  object --+        
           |        
<a href="netaddr.strategy.AddrStrategy-class.html">AddrStrategy</a> --+    
               |    
 <a href="netaddr.strategy.IPv4StrategyStd-class.html">IPv4StrategyStd</a> --+
                   |
                  <strong class="uidshort">IPv4StrategyOpt</strong>
</pre>

<hr />
<p>An optimised <a href="netaddr.strategy.AddrStrategy-class.html" 
  class="link">AddrStrategy</a> for IPv4 addresses.</p>
  <p>It uses <code>pack()</code> and <code>unpack()</code> from the 
  <code>struct</code> module along with the <code>inet_ntoa()</code> and 
  <code>inet_aton()</code> from the <code>socket</code> module great 
  improve the speed of certain operations (approx. 2.5 times faster than a 
  standard <a href="netaddr.strategy.AddrStrategy-class.html" 
  class="link">AddrStrategy</a> configured for IPv4).</p>
  <p>However, keep in mind that these modules might not be available 
  everywhere that Python itself is. Runtimes such as Google App Engine gut 
  the <code>socket</code> module. <code>struct</code> is also limited to 
  processing 32-bit integers which is fine for IPv4 but isn't suitable for 
  IPv6.</p>

<!-- ==================== INSTANCE METHODS ==================== -->
<a name="section-InstanceMethods"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Instance Methods</span></td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="netaddr.strategy.IPv4StrategyOpt-class.html#__init__" class="summary-sig-name">__init__</a>(<span class="summary-sig-arg">self</span>)</span><br />
      Constructor.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.__init__">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="netaddr.strategy.IPv4StrategyOpt-class.html#valid_str" class="summary-sig-name">valid_str</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">addr</span>)</span><br />
      Returns:
      <code>True</code> if network address in string form is valid for this
      address type, <code>False</code> otherwise.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.valid_str">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="netaddr.strategy.IPv4StrategyOpt-class.html#str_to_int" class="summary-sig-name">str_to_int</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">addr</span>)</span><br />
      Returns:
      A network byte order integer that is equivalent to value represented 
      by the IPv4 dotted decimal address string.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.str_to_int">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="netaddr.strategy.IPv4StrategyOpt-class.html#int_to_str" class="summary-sig-name">int_to_str</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">int_val</span>)</span><br />
      Returns:
      An IPv4 dotted decimal address string that is equivalent to value 
      represented by a 32 bit integer in network byte order.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.int_to_str">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="netaddr.strategy.IPv4StrategyOpt-class.html#int_to_words" class="summary-sig-name">int_to_words</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">int_val</span>,
        <span class="summary-sig-arg">num_words</span>=<span class="summary-sig-default">None</span>,
        <span class="summary-sig-arg">word_size</span>=<span class="summary-sig-default">None</span>)</span><br />
      Returns:
      An integer word (octet) sequence that is equivalent to value 
      represented by network byte order integer.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.int_to_words">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="netaddr.strategy.IPv4StrategyOpt-class.html#words_to_int" class="summary-sig-name">words_to_int</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">octets</span>)</span><br />
      Returns:
      A network byte order integer that is equivalent to value represented 
      by word (octet) sequence.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.words_to_int">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code><a href="netaddr.strategy.IPv4StrategyStd-class.html">IPv4StrategyStd</a></code></b>:
      <code><a href="netaddr.strategy.IPv4StrategyStd-class.html#int_to_arpa">int_to_arpa</a></code>
      </p>
    <p class="indent-wrapped-lines"><b>Inherited from <code><a href="netaddr.strategy.AddrStrategy-class.html">AddrStrategy</a></code></b>:
      <code><a href="netaddr.strategy.AddrStrategy-class.html#__repr__">__repr__</a></code>,
      <code><a href="netaddr.strategy.AddrStrategy-class.html#bits_to_int">bits_to_int</a></code>,
      <code><a href="netaddr.strategy.AddrStrategy-class.html#int_to_bin">int_to_bin</a></code>,
      <code><a href="netaddr.strategy.AddrStrategy-class.html#int_to_bits">int_to_bits</a></code>,
      <code><a href="netaddr.strategy.AddrStrategy-class.html#int_to_packed">int_to_packed</a></code>,
      <code><a href="netaddr.strategy.AddrStrategy-class.html#packed_to_int">packed_to_int</a></code>,
      <code><a href="netaddr.strategy.AddrStrategy-class.html#valid_bits">valid_bits</a></code>,
      <code><a href="netaddr.strategy.AddrStrategy-class.html#valid_int">valid_int</a></code>,
      <code><a href="netaddr.strategy.AddrStrategy-class.html#valid_words">valid_words</a></code>
      </p>
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__delattr__</code>,
      <code>__getattribute__</code>,
      <code>__hash__</code>,
      <code>__new__</code>,
      <code>__reduce__</code>,
      <code>__reduce_ex__</code>,
      <code>__setattr__</code>,
      <code>__str__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== CLASS VARIABLES ==================== -->
<a name="section-ClassVariables"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Class Variables</span></td>
</tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code><a href="netaddr.strategy.AddrStrategy-class.html">AddrStrategy</a></code></b>:
      <code><a href="netaddr.strategy.AddrStrategy-class.html#STRUCT_FORMATS">STRUCT_FORMATS</a></code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== PROPERTIES ==================== -->
<a name="section-Properties"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Properties</span></td>
</tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__class__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== METHOD DETAILS ==================== -->
<a name="section-MethodDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Method Details</span></td>
</tr>
</table>
<a name="__init__"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">__init__</span>(<span class="sig-arg">self</span>)</span>
    <br /><em class="fname">(Constructor)</em>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.__init__">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Constructor.</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>width</code></strong> - size of address in bits. (e.g. 32 - IPv4, 48 - MAC, 128 - IPv6)</li>
        <li><strong class="pname"><code>word_size</code></strong> - size of each word. (e.g. 8 - octets, 16 - hextets)</li>
        <li><strong class="pname"><code>word_sep</code></strong> - separator between each word. (e.g. '.' - IPv4, ':' - IPv6, '-' - 
          EUI-48)</li>
        <li><strong class="pname"><code>word_fmt</code></strong> - format string for each word. (Default: '%x')</li>
        <li><strong class="pname"><code>addr_type</code></strong> - address type. (Default: AT_UNSPEC)</li>
        <li><strong class="pname"><code>word_base</code></strong> - number base used to convert each word using int(). (Default: 16)</li>
        <li><strong class="pname"><code>uppercase</code></strong> - uppercase address. (Default: False)</li>
    </ul></dd>
    <dt>Overrides:
        object.__init__
    </dt>
  </dl>
</td></tr></table>
</div>
<a name="valid_str"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">valid_str</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">addr</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.valid_str">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>addr</code></strong> - An IP address in presentation (string) format.</li>
    </ul></dd>
    <dt>Returns:</dt>
        <dd><code>True</code> if network address in string form is valid for 
          this address type, <code>False</code> otherwise.</dd>
    <dt>Overrides:
        <a href="netaddr.strategy.AddrStrategy-class.html#valid_str">AddrStrategy.valid_str</a>
    </dt>
  </dl>
</td></tr></table>
</div>
<a name="str_to_int"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">str_to_int</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">addr</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.str_to_int">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>addr</code></strong> - An IPv4 dotted decimal address in string form.</li>
    </ul></dd>
    <dt>Returns:</dt>
        <dd>A network byte order integer that is equivalent to value 
          represented by the IPv4 dotted decimal address string.</dd>
    <dt>Overrides:
        <a href="netaddr.strategy.AddrStrategy-class.html#str_to_int">AddrStrategy.str_to_int</a>
    </dt>
  </dl>
</td></tr></table>
</div>
<a name="int_to_str"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">int_to_str</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">int_val</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.int_to_str">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>int_val</code></strong> - A network byte order integer.</li>
    </ul></dd>
    <dt>Returns:</dt>
        <dd>An IPv4 dotted decimal address string that is equivalent to value
          represented by a 32 bit integer in network byte order.</dd>
    <dt>Overrides:
        <a href="netaddr.strategy.AddrStrategy-class.html#int_to_str">AddrStrategy.int_to_str</a>
    </dt>
  </dl>
</td></tr></table>
</div>
<a name="int_to_words"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">int_to_words</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">int_val</span>,
        <span class="sig-arg">num_words</span>=<span class="sig-default">None</span>,
        <span class="sig-arg">word_size</span>=<span class="sig-default">None</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.int_to_words">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>int_val</code></strong> - A network byte order integer.</li>
        <li><strong class="pname"><code>num_words</code></strong> - (unused) *** interface compatibility only ***</li>
        <li><strong class="pname"><code>word_size</code></strong> - (unused) *** interface compatibility only ***</li>
    </ul></dd>
    <dt>Returns:</dt>
        <dd>An integer word (octet) sequence that is equivalent to value 
          represented by network byte order integer.</dd>
    <dt>Overrides:
        <a href="netaddr.strategy.AddrStrategy-class.html#int_to_words">AddrStrategy.int_to_words</a>
    </dt>
  </dl>
</td></tr></table>
</div>
<a name="words_to_int"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">words_to_int</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">octets</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="netaddr.strategy-pysrc.html#IPv4StrategyOpt.words_to_int">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>octets</code></strong> - A list or tuple containing integer octets.</li>
    </ul></dd>
    <dt>Returns:</dt>
        <dd>A network byte order integer that is equivalent to value 
          represented by word (octet) sequence.</dd>
    <dt>Overrides:
        <a href="netaddr.strategy.AddrStrategy-class.html#words_to_int">AddrStrategy.words_to_int</a>
    </dt>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="netaddr-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            >netaddr</th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Wed Jan 21 23:41:06 2009
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
